package com.jiaai.cloud.base.util;

import java.util.Calendar;

/**
 * 属相和星座工具类
 * Created by Administrator on 2017/8/15.
 */
public class Constellation {

    private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };
    private final static String[] constellationArr = new String[] { "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" };


    //属相
    public static String getYear(Integer year){
        if(year<1900){
            return "未知";
        }
        Integer start=1900;
        String [] years=new String[]{
                "鼠","牛","虎","兔",
                "龙","蛇","马","羊",
                "猴","鸡","狗","猪"
        };
        return years[(year-start)%years.length];
    }


    //星座
    public static String getConstellation(int month, int day) {
        return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];
    }


    //年龄
    public static int getAge(int year,int month, int day) {
        Calendar src = Calendar.getInstance();
        int annual0= src.get(Calendar.YEAR);
        int month0=src.get(Calendar.MONTH) + 1;
        int sun0=src.get(Calendar.DAY_OF_MONTH);
        if (month<=month0){
            if (day<=sun0){
                return annual0-year;
            }else{
                return annual0-(year+1);
            }
        }else{
           return annual0-(year+1);
        }
    }
}
